package com.hliushi.learn.utils;

import com.hliushi.learn.config.AuditProperties;
import com.hliushi.learn.config.MicroServiceUrl;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * 使用SpringContextHolder工具类, 在静态代码块中为静态变量初始化 | 或直接在静态变量的后面使用工具类进行初始化都可以
 *
 * @author llhuang10
 * @date 2021/7/21 21:05
 */
public class Prop02Util {

    public static AuditProperties auditProperties;
    public static StringRedisTemplate stringRedisTemplate;
    public static MicroServiceUrl microServiceUrl = SpringContextHolder.getBean(MicroServiceUrl.class);

    static {
        auditProperties = SpringContextHolder.getBean(AuditProperties.class);
        // bean = SpringContextHolder.getBean(MicroServiceUrl.class);
    }

    /**
     * 私有构造器, 不允许该类被实例化
     */
    private Prop02Util() {
    }

    public static MicroServiceUrl getMicroServiceUrl() {
        return microServiceUrl;
    }

    public static StringRedisTemplate getRedisTemplate() {
        return stringRedisTemplate;
    }

    public static AuditProperties getAuditProp() {
        // auditProperties  ERROR: 无法从静态上下文中引用非静态字段'auditProperties'
        return auditProperties;
    }
}
